//
//  DRCookDataModel.m
//  DoctorRen
//
//  Created by Lemon on 2018/11/21.
//

#import "DRCookDataModel.h"

@implementation DRCookDataModel

+(void)loadFriendCircleData:(DRHttpModel *)request andSuccess:(void (^)(NSArray<DRCookSociaModel *> * _Nonnull))succBlock andFail:(RequestFail)failBlock{
    
    [request startRequestSuccess:^(id data) {
        NSLog(@"%@",data);
        if (succBlock) {
            NSArray<DRCookSociaModel *>  *models = [NSArray yy_modelArrayWithClass:[DRCookSociaModel class] json:data[@"zydynamic"]];
            succBlock(models);
        }
        
    } andFail:failBlock];
}

+(void)loadLearnCookingData:(DRHttpModel *)request andSuccess:(void (^)(NSArray<DRLearnCookingModel *> * _Nonnull))succBlock andFail:(RequestFail)failBlock{
    [request startRequestSuccess:^(id data) {
//        NSLog(@"%@",data);
        if (succBlock) {
            NSArray<DRLearnCookingModel *>  *models = [NSArray yy_modelArrayWithClass:[DRLearnCookingModel class] json:data[@"cookingart"]];
            succBlock(models);
        }
        
    } andFail:failBlock];
    
}

+(void)giveLike:(NSString *)c_id andSuccess:(void (^)(NSInteger))succBlock andFail:(RequestFail)failBlock{
    
    [[DRHttpTool shared].manager GET:DRURL(@"/index.php/Apicookingart/good") parameters:@{@"token": [DRLoginDataModel getUserToken] , @"id" : c_id} progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        DRResponseModel *data = [DRResponseModel yy_modelWithJSON:responseObject];
        if (data.error == -1 || data.error == 0) {
            if (succBlock) {
                succBlock(data.error);
            }
        }else{
            if(failBlock){
                NSString *domain = @"com.DR.ErrorDomain";
                NSString *desc = NSLocalizedString(data.msg ,nil);
                NSDictionary *userInfo = @{ NSLocalizedDescriptionKey : desc };
                NSError *error = [NSError errorWithDomain:domain
                                                     code:-101
                                                 userInfo:userInfo];
                failBlock(error);
            }
        }
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failBlock) {
            failBlock(error);
        }
    }];
}

+(void)giveLikeHealthy:(NSString *)l_id isLike:(BOOL)isLike andSuccess:(void (^)(void))succBlock andFail:(RequestFail)failBlock{
    
    NSString *type = isLike ? @"del" : @"add";
    
    [[DRHttpTool shared] new_POST:DRURL(@"index.php/Cookingart/likeHealthy")
                        andParams:@{
                                    @"id": l_id,
                                    @"type": type,
                                    @"token": [DRLoginDataModel getUserToken]
                                    }
                          andSucc:^(id  _Nonnull data) {
        
                              if (succBlock) {
                                  succBlock();
                              }
    
                          } andFail:failBlock];
    
}

+(void)comment:(NSString *)c_id content:(NSString *)content andSuccess:(void (^)(void))succBlock andFail:(RequestFail)failBlock{
    [[DRHttpTool shared] POST:DRURL(@"/index.php/Apicookingart/commonts")
                    andParams:@{@"token": [DRLoginDataModel getUserToken] ,
                                @"id" : c_id,
                                @"content": content
                                }
                      andSucc:^(id  _Nonnull data) {
                          
                          if (succBlock){
                              succBlock();
                          }
                      }
                      andFail:failBlock];
}

@end
